package main

import (
	"github.com/gin-gonic/gin"
	"go-admin/global"
	myCas "go-admin/global/casbin"
	"go-admin/global/db"
	"go-admin/global/minio"
	"go-admin/internal/routers"
	"go-admin/pkg/language_translator"
	"log"
	"net/http"
)

func init() {
	if err := global.SetupSetting(); err != nil {
		log.Fatalf("初始化 SetupSetting 方法失败: %v", err)
	}
	if err := global.SetupSnowflake("2020-01-01", 1); err != nil {
		log.Fatalf("初始化 SetupSnowflake 方法失败：%v", err)
	}
	if err := db.SetupDBEngine(); err != nil {
		log.Fatalf("初始化 SetupDBEngine 方法失败：%v", err)
	}
	if err := global.SetupLogger(); err != nil {
		log.Fatalf("初始化 SetupLogger 方法失败：%v", err)
	}
	if err := language_translator.SetupTrans(); err != nil {
		log.Fatalf("初始化 SetupTrans 方法失败：%v", err)
	}
	if err := global.SetupEmailSetting(); err != nil {
		log.Fatalf("初始化 SetupEmailSetting 方法失败：%v", err)
	}
	if err := myCas.CasbinEnforcer(); err != nil {
		log.Fatalf("初始化 CasbinEnforcer 方法失败：%v", err)
	}
	if err := minio.SetupMinio(); err != nil {
		log.Fatalf("初始化 SetupMinio 方法失败：%v", err)
	}
}

// @title go-admin
// @version 1.0
// @description go-admin接口的文档
func main() {
	gin.SetMode(global.ServerSetting.RunMode)
	router := routers.NewRouter()
	server := &http.Server{
		Addr:           ":" + global.ServerSetting.HttpPort,
		Handler:        router,
		ReadTimeout:    global.ServerSetting.ReadTimeout,
		WriteTimeout:   global.ServerSetting.WriteTimeout,
		MaxHeaderBytes: 1 << 20,
	}
	server.ListenAndServe()
}
